﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Site.Master"
    CodeBehind="SiteManager.aspx.vb" Inherits="mybaconrecipe.SiteManager" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h1 style="margin-bottom: 0px;">
        Site Manager
    </h1>
    <div class="fullWidthPane">
        <asp:TabContainer ID="siteManagerTabContainer" runat="server" ActiveTabIndex="0"
            CssClass="MyTabStyle" Width="960px">
            <!-- TAB 1 - SITE STATISTICS -->
            <asp:TabPanel runat="server" HeaderText="Site Stats" ID="tab_Stats">
                <ContentTemplate>
                    <table cellpadding="0" cellspacing="0" class="statTable">
                        <tr>
                            <td>
                                <h2>
                                    Overview</h2>
                            </td>
                        </tr>
                        <tr>
                            <th class="visHeader">
                                Recipe Views By Month
                            </th>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <asp:Literal ID="ltr_SiteViews" runat="server"></asp:Literal><div id="div_siteViews">
                                </div>
                            </td>
                        </tr>
                       <tr>
                            <th class="visHeader">
                                Registered Users By Country
                            </th>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <asp:Literal ID="ltr_UsersCountry" runat="server"></asp:Literal><div id="div_usersCountry">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <th class="visHeader">
                                Recipes In Each Category
                            </th>
                        </tr>
                        <tr>
                            <td style="text-align: center;">
                                <asp:Literal ID="ltr_Pie_RecCategories" runat="server"></asp:Literal><div id="div_recCategories">
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <h2>
                                    Top Lists</h2>
                            </td>
                        </tr>
                    </table>
                    <table cellpadding="0" cellspacing="0" class="statTable">
                        <tr>
                            <th class="LHS">
                                Most Viewed Recipes
                            </th>
                            <th class="MID">
                                &nbsp;
                            </th>
                            <th class="RHS">
                                Users Who Uploaded Most Recipes
                            </th>
                        </tr>
                        <tr>
                            <td class="LHS">
                                <asp:GridView ID="grd_StatTopRecipesViewed" runat="server" AutoGenerateColumns="False"
                                    DataSourceID="statRecipeNumViewsSqlDataSource" CssClass="grd_profileRecipeStyle"
                                    AllowPaging="True">
                                    <Columns>
                                        <asp:TemplateField HeaderText="Recipe">
                                            <ItemTemplate>
                                                <div style="width: 350px;">
                                                    <a href='<%# DataBinder.Eval(Container.DataItem, "RECIPE_ID", "RecipeDetail.aspx?ID={0}") %>'>
                                                        <%# DataBinder.Eval(Container.DataItem, "REC_NAME") %></a></div>
                                            </ItemTemplate>
                                            <ControlStyle CssClass="EightyWidth" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="TopViewedRec" HeaderText="Views" SortExpression="TopViewedRec">
                                        </asp:BoundField>
                                    </Columns>
                                    <HeaderStyle CssClass="statHeader" />
                                </asp:GridView>
                                <asp:SqlDataSource ID="statRecipeNumViewsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                                    ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [STAT_RECIPE_NUMVIEWS_VIEW]">
                                </asp:SqlDataSource>
                            </td>
                            <td class="MID">
                                &nbsp;
                            </td>
                            <td class="RHS">
                                <asp:GridView ID="grd_StatTopUsersRecipes" runat="server" AutoGenerateColumns="False"
                                    DataSourceID="StatUserNumRecipesSqlDataSource" CssClass="grd_profileRecipeStyle"
                                    AllowPaging="True">
                                    <Columns>
                                        <asp:TemplateField HeaderText="User">
                                            <ItemTemplate>
                                                <div style="width: 350px;">
                                                    <a href='<%# DataBinder.Eval(Container.DataItem, "USER_UNAME", "Profile.aspx?User={0}") %>'>
                                                        <%# DataBinder.Eval(Container.DataItem, "USER_FNAME")%>
                                                        <%# DataBinder.Eval(Container.DataItem, "USER_LNAME")%></a></div>
                                            </ItemTemplate>
                                            <ControlStyle CssClass="EightyWidth" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="NumRecipes" HeaderText="Recipes" SortExpression="NumRecipes" />
                                    </Columns>
                                    <HeaderStyle CssClass="statHeader" />
                                </asp:GridView>
                                <asp:SqlDataSource ID="StatUserNumRecipesSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                                    ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [NUM_RECIPE_VIEW]">
                                </asp:SqlDataSource>
                            </td>
                        </tr>
                        <tr>
                            <th class="LHS">
                                Highest Rated Recipes
                            </th>
                            <th class="MID">
                                &nbsp;
                            </th>
                            <th class="RHS">
                                Most Rated Recipes
                            </th>
                        </tr>
                        <tr>
                            <td class="LHS">
                                <asp:GridView ID="grd_StatTopRecipesAvgRated" runat="server" AutoGenerateColumns="False"
                                    DataSourceID="StatRecipeNumAvgRatingDataSource" CssClass="grd_profileRecipeStyle"
                                    AllowPaging="True">
                                    <Columns>
                                        <asp:TemplateField HeaderText="Recipe">
                                            <ItemTemplate>
                                                <div style="width: 350px;">
                                                    <a href='<%# DataBinder.Eval(Container.DataItem, "RECIPE_ID", "RecipeDetail.aspx?ID={0}") %>'>
                                                        <%# DataBinder.Eval(Container.DataItem, "REC_NAME") %></a></div>
                                            </ItemTemplate>
                                            <ControlStyle CssClass="EightyWidth" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="AverageRating" HeaderText="Rating" ReadOnly="True" SortExpression="AverageRating" DataFormatString="{0:0.00}" />
                                    </Columns>
                                    <HeaderStyle CssClass="statHeader" />
                                </asp:GridView>
                                <asp:SqlDataSource ID="StatRecipeNumAvgRatingDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                                    ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [STAT_TOTAL_AVG_RATING]">
                                </asp:SqlDataSource>
                            </td>
                            <td class="MID">
                                &nbsp;
                            </td>
                            <td class="RHS">
                                <asp:GridView ID="grd_StatTopRecipesRated" runat="server" AutoGenerateColumns="False"
                                    DataSourceID="StatRecipeNumRatingDataSource" CssClass="grd_profileRecipeStyle"
                                    AllowPaging="True">
                                    <Columns>
                                        <asp:TemplateField HeaderText="Recipe">
                                            <ItemTemplate>
                                                <div style="width: 350px;">
                                                    <a href='<%# DataBinder.Eval(Container.DataItem, "RECIPE_ID", "RecipeDetail.aspx?ID={0}") %>'>
                                                        <%# DataBinder.Eval(Container.DataItem, "REC_NAME") %></a></div>
                                            </ItemTemplate>
                                            <ControlStyle CssClass="EightyWidth" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="TotalRatings" HeaderText="Times" SortExpression="TotalRatings" />
                                    </Columns>
                                    <HeaderStyle CssClass="statHeader" />
                                </asp:GridView>
                                <asp:SqlDataSource ID="StatRecipeNumRatingDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                                    ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [STAT_TOTAL_RATING]">
                                </asp:SqlDataSource>
                            </td>
                        </tr>
                        <tr>
                            <th class="LHS">
                                Users Who Rated Most
                            </th>
                            <th class="MID">
                                &nbsp;
                            </th>
                            <th class="RHS">
                                Users Who Commented Most
                            </th>
                        </tr>
                        <tr>
                            <td class="LHS">
                                <asp:GridView ID="grd_StatUserRating" runat="server" AutoGenerateColumns="False"
                                    DataSourceID="StatUserNumRatingSqlDataSource" CssClass="grd_profileRecipeStyle"
                                    AllowPaging="True">
                                    <Columns>
                                        <asp:TemplateField HeaderText="User">
                                            <ItemTemplate>
                                                <div style="width: 350px;">
                                                    <a href='<%# DataBinder.Eval(Container.DataItem, "USER_UNAME", "Profile.aspx?User={0}") %>'>
                                                        <%# DataBinder.Eval(Container.DataItem, "USER_FNAME")%>
                                                        <%# DataBinder.Eval(Container.DataItem, "USER_LNAME")%></a></div>
                                            </ItemTemplate>
                                            <ControlStyle CssClass="EightyWidth" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="TtlUserRating" HeaderText="Ratings" SortExpression="TtlUserRating" />
                                    </Columns>
                                    <HeaderStyle CssClass="statHeader" />
                                </asp:GridView>
                                <asp:SqlDataSource ID="StatUserNumRatingSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                                    ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [STAT_TOTAL_RATING_USER]">
                                </asp:SqlDataSource>
                            </td>
                            <td class="MID">
                            </td>
                            <td class="RHS">
                                <asp:GridView ID="grd_StatUserComments" runat="server" AutoGenerateColumns="False"
                                    DataSourceID="StatUserNumCommentsSqlDataSource" CssClass="grd_profileRecipeStyle"
                                    AllowPaging="True">
                                    <Columns>
                                        <asp:TemplateField HeaderText="User">
                                            <ItemTemplate>
                                                <div style="width: 350px;">
                                                    <a href='<%# DataBinder.Eval(Container.DataItem, "USER_UNAME", "Profile.aspx?User={0}") %>'>
                                                        <%# DataBinder.Eval(Container.DataItem, "USER_FNAME")%>
                                                        <%# DataBinder.Eval(Container.DataItem, "USER_LNAME")%></a></div>
                                            </ItemTemplate>
                                            <ControlStyle CssClass="EightyWidth" />
                                        </asp:TemplateField>
                                        <asp:BoundField DataField="NumComments" HeaderText="Comments" SortExpression="NumComments" />
                                    </Columns>
                                    <HeaderStyle CssClass="statHeader" />
                                </asp:GridView>
                                <asp:SqlDataSource ID="StatUserNumCommentsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                                    ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [NUM_COMMENTS_VIEW]">
                                </asp:SqlDataSource>
                            </td>
                        </tr>
                    </table>
                </ContentTemplate>
            </asp:TabPanel>

            <!-- TAB 2 - ALL RECIPES -->
            <asp:TabPanel ID="tab_Recipes" runat="server" HeaderText="All Recipes">
                <ContentTemplate>
                    <asp:GridView ID="grd_AllRecipes" runat="server" AutoGenerateColumns="False" DataKeyNames="REC_ID"
                        DataSourceID="AllRecipesSqlDataSource" CssClass="grd_profileRecipeStyle" PageSize="20">
                        <Columns>
                            <asp:ImageField DataImageUrlField="REC_IMAGE">
                                <ControlStyle CssClass="activityThumb" />
                            </asp:ImageField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <span class="profileDate">
                                        <%# Eval("REC_DATE")%></span><br />
                                    <a href='<%# DataBinder.Eval(Container.DataItem, "REC_ID", "RecipeDetail.aspx?ID={0}") %>'>
                                        <%# DataBinder.Eval(Container.DataItem, "REC_NAME") %></a>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <a href='<%# DataBinder.Eval(Container.DataItem, "REC_ID", "EditRecipe.aspx?ID={0}") %>'>
                                        <img src="ui/icnEdit.png" class="frmIcon" title="Edit Recipe" alt="Edit Recipe" /></a>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <a href='<%# DataBinder.Eval(Container.DataItem, "REC_ID", "DeleteRecipe.aspx?ID={0}") %>'>
                                        <img src="ui/icnDelete.png" class="frmIconDel" title="Delete Recipe" alt="Delete Recipe" /></a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <HeaderStyle CssClass="notVis" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="AllRecipesSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                        ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [RECIPE] ORDER BY REC_DATE DESC">
                    </asp:SqlDataSource>
                </ContentTemplate>
            </asp:TabPanel>
            
            <!-- TAB 3 - ALL USERS -->
            <asp:TabPanel ID="tab_Users" runat="server" HeaderText="All Users">
                <ContentTemplate>
                    <asp:GridView ID="grd_AllUsers" runat="server" AutoGenerateColumns="False" DataKeyNames="PROFILE_ID"
                        DataSourceID="AllUsersDataSource" CssClass="grd_profileRecipeStyle" PageSize="20">
                        <Columns>
                            <asp:ImageField DataImageUrlField="USER_PHOTO">
                                <ControlStyle CssClass="recDetailUserPhoto" />
                            </asp:ImageField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <span class="profileDate" style="text-transform:none;">
                                        <%# "USERNAME: " & Eval("USER_UNAME")%></span><br />
                                    <a href='<%# DataBinder.Eval(Container.DataItem, "USER_UNAME", "Profile.aspx?User={0}") %>'>
                                        <%# DataBinder.Eval(Container.DataItem, "USER_FNAME")%>
                                        <%# DataBinder.Eval(Container.DataItem, "USER_LNAME")%></a>
                                </ItemTemplate>
                            </asp:TemplateField>

                           <asp:TemplateField HeaderText="Header" SortExpression="Field">
                               <ItemTemplate>
                                   <asp:HyperLink ID="hyp_BlockUser" runat="server" visible='<%# Eval("USER_BLCKD") = "False"%>' NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "USER_UNAME", "BlockUser.aspx?User={0}") %>'>Block User</asp:HyperLink>
                                   <asp:HyperLink ID="hyp_UnblockUser" runat="server" visible='<%# Eval("USER_BLCKD") = "True"%>' NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "USER_UNAME", "UnblockUser.aspx?User={0}") %>' CssClass="redLink">Unblock User</asp:HyperLink>
                                </ItemTemplate>
                            </asp:TemplateField>

                        </Columns>
                        <HeaderStyle CssClass="notVis" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="AllUsersDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                        ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [PROFILE] ORDER BY USER_FNAME">
                    </asp:SqlDataSource>
                </ContentTemplate>
            </asp:TabPanel>

            <!-- TAB 4 - ALL COMMENTS -->
            <asp:TabPanel ID="tab_Comments" runat="server" HeaderText="All Comments">
                <ContentTemplate>
                    <asp:GridView runat="server" ID="grd_AllComments" AutoGenerateColumns="False" DataSourceID="AllCommentsDataSource"
                        CssClass="grd_profileRecipeStyle" PageSize="20">
                        <Columns>
                            <asp:ImageField DataImageUrlField="REC_IMAGE">
                                <ControlStyle CssClass="activityThumb" />
                            </asp:ImageField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <span class="profileDate">
                                        <%# Eval("COMM_DATE")%></span><br />
                                    <span class="profileDate">ON: </span><a href='<%# DataBinder.Eval(Container.DataItem, "REC_ID", "RecipeDetail.aspx?ID={0}") %>'>
                                        <%# DataBinder.Eval(Container.DataItem, "REC_NAME") %></a><br />
                                    <p class="profileCommStyle">
                                        <%# Eval("COMM_DESC")%></p>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <a href='<%# DataBinder.Eval(Container.DataItem, "COMM_ID", "DeleteComment.aspx?ID={0}") %>'>
                                        <img src="ui/icnDelete.png" class="frmIconDel" title="Delete Comment" alt="Delete Comment" /></a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <HeaderStyle CssClass="notVis" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="AllCommentsDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                        ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [PROFILE_COMMENT_RECIPE_VIEW] ORDER BY COMM_DATE DESC">
                    </asp:SqlDataSource>
                </ContentTemplate>
            </asp:TabPanel>

            <!-- TAB 5 - ALL RATINGS -->
            <asp:TabPanel ID="tab_Ratings" runat="server" HeaderText="All Ratings">
                <ContentTemplate>
                    <asp:GridView ID="grd_AllRatings" runat="server" AutoGenerateColumns="False" DataSourceID="AllRatingsSqlDataSource"
                        CssClass="grd_profileRecipeStyle" PageSize="20">
                        <Columns>
                            <asp:ImageField DataImageUrlField="REC_IMAGE">
                                <ControlStyle CssClass="activityThumb" />
                            </asp:ImageField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <span class="profileDate">
                                        <%# Eval("RATING_DATE")%></span><br />
                                    <span class="profileDate">ON: </span><a href='<%# DataBinder.Eval(Container.DataItem, "REC_ID", "RecipeDetail.aspx?ID={0}") %>'>
                                        <%# DataBinder.Eval(Container.DataItem, "REC_NAME") %></a><br />
                                    <p class="profileCommStyle">
                                        <%# Eval("RATING_VALUE") & " Bacon Strips" %></p>
                                </ItemTemplate>
                            </asp:TemplateField>
                            <asp:TemplateField>
                                <ItemTemplate>
                                    <a href='<%# DataBinder.Eval(Container.DataItem, "RATING_ID", "DeleteRating.aspx?ID={0}") %>'>
                                        <img src="ui/icnDelete.png" class="frmIconDel" title="Delete Rating" alt="Delete Rating" /></a>
                                </ItemTemplate>
                            </asp:TemplateField>
                        </Columns>
                        <HeaderStyle CssClass="notVis" />
                    </asp:GridView>
                    <asp:SqlDataSource ID="AllRatingsSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:recipeConnectionString %>"
                        ProviderName="<%$ ConnectionStrings:recipeConnectionString.ProviderName %>" SelectCommand="SELECT * FROM [PROFILE_RATING_RECIPE_VIEW] ORDER BY RATING_DATE DESC">
                    </asp:SqlDataSource>
                </ContentTemplate>
            </asp:TabPanel>
        </asp:TabContainer>
        <asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">
        </asp:ToolkitScriptManager>
    </div>
</asp:Content>
